﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SaleReturn.aspx.cs" Culture="en-GB" Inherits="Main_Reports_Inventory_TransactionRegister_SaleReturn" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<%@ Register Src="~/User Controls/PageHeading.ascx" TagName="heading" TagPrefix="acc" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Sale Return</title>
    <link href="../../../../Styles/accounts.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript" language="javascript">
        function checkdate() {
            if (document.getElementById("txtfrom").value == '') {
                alert('Specify From date!');
                document.getElementById("txtfrom").focus();
                return false;
            }
            else if (document.getElementById("txtto").value == '') {
                alert('Specify To Date!');
                document.getElementById("txtto").focus();
                return false;
            }
            else {
                var strFromDate = document.getElementById("txtfrom").value;
                var strToDate = document.getElementById("txtto").value;
                var dtFrom = parseInt(strFromDate.substring(0, 2), 10);
                var monFrom = parseInt(strFromDate.substring(3, 5), 10);
                var yrFrom = parseInt(strFromDate.substring(6, 10), 10);
                var dtTo = parseInt(strToDate.substring(0, 2), 10);
                var monTo = parseInt(strToDate.substring(3, 5), 10);
                var yrTo = parseInt(strToDate.substring(6, 10), 10);
                var dateFrom = new Date(yrFrom, monFrom, dtFrom);
                var dateTo = new Date(yrTo, monTo, dtTo);
                if (dateTo < dateFrom) {
                    alert("from date cannot be greater than to date");
                    document.getElementById("txtfrom").focus();
                    return false;
                }
                else {
                    return true;
                }
            }
        }
        function EnabledTabKey(id, e) {
            var keycode;
            if (window.event) {
                keycode = window.event.keyCode;
            }
            else if (e) {
                keycode = e.which;
            }
            else {
                return true;
            }

            if (keycode == 9) {
                // if is the tab key                
                return true;
            }
            else {
                return false;
            }
        }
        function Validation() {
            var flag = true;
            var txtFromdate = document.getElementById("txtFromDate").id;
            var txtTodate = document.getElementById("txtToDate").id;
            if (document.getElementById("txtFromDate").value == '') {
                alert('Specify From date');
                flag = false;
            }
            else if (document.getElementById("txtToDate").value == '') {
                alert('Specify To date');
                flag = false;
            }
            else {
                if (isDate(txtFromdate) && isDate(txtTodate)) {
                    var dateArray = new Array();
                    dateArray = document.getElementById("txtFromDate").value.split("/");
                    var day1 = dateArray[0];
                    var month1 = dateArray[1];
                    var year1 = dateArray[2];
                    dateArray = document.getElementById("txtToDate").value.split("/");
                    var day2 = dateArray[0];
                    var month2 = dateArray[2];
                    var year2 = dateArray[2];

                    if (day1.length < 2) {
                        day1 = '0' + day1;
                    }
                    if (month1.length < 2) {
                        month1 = '0' + month1;
                    }
                    if (day2.length < 2) {
                        day2 = '0' + day2;
                    }
                    if (month2.length < 2) {
                        month2 = '0' + month2;
                    }
                    var date1 = new Date(year1, month1 - 1, day1);
                    var date2 = new Date(year2, month2 - 1, day2);
                    if (date1 > date2) {
                        alert('Date Could Not be less than From Date');
                        document.getElementById(txtFromdate).focus();
                        flag = false;

                    }
                }
                else {
                    flag = false;
                }
            }
            return flag;
        }
        function isDate(txtDateId) {
            // date length should be 10 characters - no more, no less            
            var Ctrl = document.getElementById(txtDateId);
            var txtDate = Ctrl.value;
            var flag = true;

            // extract day, month and year from the txtDate string
            // expected format is dd/mm/yyyy
            var day = '';
            var month = '';
            var year = '';
            var dateArray = new Array();
            var count = 0;
            for (var j = 0; j < txtDate.length; j++) {
                var chara = txtDate.charAt(j);
                if (chara == '/') {
                    count += 1;
                }
            }
            if (count != 2) {
                alert('Invalid date !');
                return false;
            }
            dateArray = txtDate.split("/");


            day = dateArray[0];
            month = dateArray[1];
            year = dateArray[2];


            if (year.length != 4) {
                alert('Invalid date !');
                return false;
            }
            var finYear = document.getElementById("hidFinyear").value;
            if (month >= 4 && year != parseInt(finYear)) {
                alert('Date Should be between 01/04/' + finYear + ' and 31/03/' + (parseInt(finYear) + 1));
                return false;
            }
            else if (month < 4 && year != (parseInt(finYear) + 1)) {
                alert('Date Should be between 01/04/' + finYear + ' and 31/03/' + (parseInt(finYear) + 1));
                return false;
            }



            if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
                if (day > 31) {
                    alert('Date Should not be Greater than 31');
                    Ctrl.focus();
                    flag = false;
                }
            }
            //for have only 30 day
            else if (month == 4 || month == 6 || month == 9 || month == 11) {
                if (day > 30) {
                    alert('Date Should not be Greater than 30');
                    Ctrl.focus();
                    flag = false;
                }
            }
            //for Febuary 
            else if (month == 2) {
                var leap = year % 4;
                if (leap == 0) {
                    if (day > 29) {
                        alert('february have only 29 days');
                        Ctrl.focus();
                        flag = false;
                    }
                }
                else {
                    if (day > 28) {
                        alert('february have only 28 days');
                        Ctrl.focus();
                        flag = false;
                    }
                }
            }
            else if (month > 12) {
                alert('Invalid Date');
                Ctrl.focus();
                flag = false;
            }
            // otherwise return true
            return flag;
        }
        function printPartOfPage() {
            var printDiv = document.getElementById("pnlPrint").innerHTML;
            var windowUrl = 'about:blank';
            var uniqueName = new Date();
            var windowName = 'Print' + uniqueName.getTime();
            var printWindow = window.open(windowUrl, windowName, 'width=10,height=10');
            printWindow.document.write('<html><link rel="stylesheet" type="text/css" href="../../../../Styles/accounts.css" /><body>');
            printWindow.document.write(printDiv);
            printWindow.document.write("</body></html>");
            printWindow.document.close();
            printWindow.focus();
            printWindow.print();
            printWindow.close();
            return false;
        }
       
        function expandDetailsInGrid(imgId, grdId) {
            var imgelem = document.getElementById(imgId);
            var rowdetelem = document.getElementById(grdId);
            if (imgelem.alt == "plus") {
                imgelem.src = "../../../../Images/minus.png";
                imgelem.alt = "minus";
                rowdetelem.style.display = "block";
            }
            else {
                imgelem.src = "../../../../Images/plus.png";
                imgelem.alt = "plus";
                rowdetelem.style.display = "none";
            }
            return false;
        }
    </script>

<style type="text/css">
    .itemclass td
    {
        font-family: verdana;
        font-size: 11px;
        font-weight: lighter;
        border-right:solid 1px #818181;
        padding:0 0 0 0;
    }
</style>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="scriptmanager1" runat="server">
    </asp:ScriptManager>
    <asp:HiddenField ID="hidfinyear" runat="server" />
    <acc:heading ID="pagehead" runat="server" HeadingText="Sale Return" />
    <div style="width: 95%; margin-left: 3%;">
        <asp:HyperLink ID="hyperChangeDate" runat="server" NavigateUrl="#" Text="Change Date"></asp:HyperLink>
        <%--&nbsp;&nbsp;&nbsp;<asp:HyperLink ID="hyplnkPrint" runat="server" NavigateUrl="#" onclick="return printPartOfPage();" Text="Print"></asp:HyperLink>--%>
        &nbsp;&nbsp;&nbsp;<asp:HyperLink ID="hyperMainMenu" runat="server" NavigateUrl="~/Main/Reports/Inventory/TransactionRegister/TransactionRegister.aspx" Text="Main Menu"></asp:HyperLink>
        <br />
        <asp:Label ID="lblCompName" runat="server"></asp:Label>
        <br />
        <asp:Panel ID="pnlDropdown" runat="server" Width="98%" BorderStyle="Solid" BorderColor="#818181" BorderWidth="1px">
         <center><b>Select Format :&nbsp;</b><asp:DropDownList ID="ddlFormatName" runat="server" OnSelectedIndexChanged="ddlFormatName_SelectedIndexChanged" CssClass="dropdown" AutoPostBack="true"></asp:DropDownList></center>
         </asp:Panel>
         <br />
         <asp:Panel ID="pnlmsg" runat="server" Visible="false" Width="98%" BorderStyle="Solid" BorderColor="#818181" BorderWidth="1px">
        <center>
            <b>
                <asp:Label ID="lblMsg" runat="server" ForeColor="Red" Text="No Record Found !" ></asp:Label></b>
                </center>
                
         </asp:Panel>
         
    </div>
    <div style="width: 93%; margin-left: 3%; margin-right: 2%;">
    <asp:Panel ID="pnlDisplay"  runat="server">
        <asp:DataList ID="dtlstSaleReturn" runat="server" Width="100%" HeaderStyle-BorderColor="#818181" HeaderStyle-BorderStyle="Solid" HeaderStyle-BorderWidth="1px" ItemStyle-BorderStyle="solid" ItemStyle-BorderWidth="1px" ItemStyle-BorderColor="#818181" CssClass="itemclass" SelectedItemStyle-VerticalAlign="Top" OnItemDataBound="dtlstSaleReturn_ItemBound">
        <HeaderTemplate>
        <table width="100%">
                    <tr>
                  <td style="width: 12%;"><b>Date</b></td>
                   <td style="width: 12%;"><b>Bill Number</b></td>
                   <td style="width: 30%;"><b>Customer Name</b></td>
                    <td style="width: 23%;"><b>Narration</b></td>
                    <td style="width: 23%;"><b>Remarks</b></td>
                    </tr>
                    </table>
        </HeaderTemplate>
               <ItemTemplate>
                <table width="100%">
                    <tr>
                        <td style="width: 12%;">
                        <asp:ImageButton runat="server" ID="imgShow" ImageUrl="../../../../Images/plus.png" AlternateText="plus" />
                         &nbsp;<asp:Label ID="lblDate" runat="server" Text='<%#string.Format("{0:dd/MMM/yyyy}", Eval("TRNDATE"))%>'></asp:Label>
                        </td>
                        <td style="width: 12%;">
                            &nbsp;
                            <asp:Label ID="lblBillNumber" runat="server" Text='<%#Eval("TRANNUMBER") %>'></asp:Label>
                        </td>
                        <td style="width: 30%;">
                            &nbsp;
                            <asp:Label ID="lblCustomerName" runat="server" Text='<%#Eval("LNAME") %>'></asp:Label>
                        </td>
                        <td style="width: 23%;">
                            &nbsp;
                            <asp:Label ID="lblNarration" runat="server" Text='<%#Eval("Narration") %>'></asp:Label>
                        </td>
                        <td style="width: 23%;">
                            &nbsp;
                            <asp:Label ID="lblRemarks" runat="server" Text='<%#Eval("Remarks") %>'></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="5">
                        
                            <asp:GridView ID="grdSaleReturnDtl" runat="server" Width="100%" OnRowDataBound="grd_RowDataBound" AutoGenerateColumns="false" CssClass="gridview" style="display:none ;margin-top:5px" >
                                <Columns>
                                   <asp:BoundField HeaderText="Item" DataField="ITMDESC" ItemStyle-Width="16%" />
                                    <asp:BoundField HeaderText="Unit" DataField="UOMSYMBOL" ItemStyle-Width="12%" />
                                    <asp:BoundField HeaderText="Qty" DataField="ITMQTY" ItemStyle-Width="12%" />
                                    <asp:BoundField HeaderText="Rate" DataField="RATE" ItemStyle-Width="12%" />
                                    <asp:BoundField HeaderText="Value" DataField="ITMVALUE" ItemStyle-Width="12%" />
                                    <asp:BoundField HeaderText="Discount" DataField="DISCAMT" ItemStyle-Width="12%" />
                                    <asp:BoundField HeaderText="Tax" DataField="TAXAMT" ItemStyle-Width="12%" />
                                    <asp:BoundField HeaderText="Total" DataField="ITMAMT" ItemStyle-Width="12%" />
                                </Columns>
                                <EmptyDataTemplate>
                                <%--<span style="font-weight:bold; color:Red;">Record Not Found!</span>--%>
                                </EmptyDataTemplate>
                            </asp:GridView>
                        </td>
                    </tr>
                </table>
            </ItemTemplate>
        </asp:DataList></asp:Panel>
    </div>
    <asp:Panel ID="pnlChangeDate" runat="server" Width="350px" Height="160px" Style="display: none"
        CssClass="modalPopup">
        <div style="width: 80%; margin: 20px 10% 10px 10%;">
            <table>
                <tr>
                    <td>
                        From Date
                    </td>
                    <td style="padding-left: 10px">
                        <asp:TextBox ID="txtFromDate" runat="server" CssClass="input" ToolTip="DD/MM/YYYY"
                            Width="100px"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>
                        To Date
                    </td>
                    <td style="padding-left: 10px">
                        <asp:TextBox ID="txtToDate" runat="server" CssClass="input" ToolTip="DD/MM/YYYY"
                            Width="100px"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td colspan="2" align="center">
                        <asp:Button ID="btnCangeDate" runat="server" CssClass="button" Text="Ok" OnClick="btnCangeDate_Click"
                            OnClientClick="return Validation();" />&nbsp;
                        <asp:Button ID="btncancel" runat="server" CssClass="button" Text="Cancel" />&nbsp;
                    </td>
                </tr>
            </table>
        </div>
    </asp:Panel>
    <ajaxtoolkit:modalpopupextender id="modalChangeDate" runat="server" cancelcontrolid="btncancel"
        targetcontrolid="hyperChangeDate" popupcontrolid="pnlChangeDate" backgroundcssclass="modalBackground">
    </ajaxtoolkit:modalpopupextender>
    <%--<asp:Panel ID="pnlPrint"  runat="server" style="display:none;">
        <asp:DataList ID="dtlstSaleReturn1" runat="server" Width="100%" HeaderStyle-BorderColor="#818181" HeaderStyle-BorderStyle="Solid" HeaderStyle-BorderWidth="1px" ItemStyle-BorderStyle="solid" ItemStyle-BorderWidth="1px" ItemStyle-BorderColor="#818181" CssClass="itemclass" SelectedItemStyle-VerticalAlign="Top" OnItemDataBound="dtlstSaleReturn1_ItemBound">
        <HeaderTemplate>
        <table width="100%">
                    <tr>
                  <td style="width: 12%;"><b>Date</b></td>
                   <td style="width: 12%;"><b>Bill Number</b></td>
                   <td style="width: 30%;"><b>Customer Name</b></td>
                    <td style="width: 23%;"><b>Narration</b></td>
                    <td style="width: 23%;"><b>Remarks</b></td>
                    </tr>
                    </table>
        </HeaderTemplate>
       
        <ItemTemplate>
                <table width="100%">
                    <tr>
                        <td style="width: 12%;">
                        &nbsp;<asp:Label ID="lblDate1" runat="server" Text='<%#string.Format("{0:dd/MMM/yyyy}", Eval("TRNDATE"))%>'></asp:Label>
                        </td>
                        <td style="width: 12%;">
                            &nbsp;
                            <asp:Label ID="lblBillNumber1" runat="server" Text='<%#Eval("TRANNUMBER") %>'></asp:Label>
                        </td>
                        <td style="width: 30%;">
                            &nbsp;
                            <asp:Label ID="lblCustomerName1" runat="server" Text='<%#Eval("LNAME") %>'></asp:Label>
                        </td>
                        <td style="width: 23%;">
                            &nbsp;
                            <asp:Label ID="lblNarration1" runat="server" Text='<%#Eval("Narration") %>'></asp:Label>
                        </td>
                        <td style="width: 23%;">
                            &nbsp;
                            <asp:Label ID="lblRemarks1" runat="server" Text='<%#Eval("Remarks") %>'></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="5">
                        
                            <asp:GridView ID="grdSaleReturnDtl1" runat="server" Width="100%" OnRowDataBound="grd1_RowDataBound" AutoGenerateColumns="false" CssClass="gridview" style="margin-top:5px" >
                                <Columns>
                                   <asp:BoundField HeaderText="Item" DataField="ITMDESC" ItemStyle-Width="16%" />
                                    <asp:BoundField HeaderText="Unit" DataField="UOMSYMBOL" ItemStyle-Width="12%" />
                                    <asp:BoundField HeaderText="Qty" DataField="ITMQTY" ItemStyle-Width="12%" />
                                    <asp:BoundField HeaderText="Rate" DataField="RATE" ItemStyle-Width="12%" />
                                    <asp:BoundField HeaderText="Value" DataField="ITMVALUE" ItemStyle-Width="12%" />
                                    <asp:BoundField HeaderText="Discount" DataField="DISCAMT" ItemStyle-Width="12%" />
                                    <asp:BoundField HeaderText="Tax" DataField="TAXAMT" ItemStyle-Width="12%" />
                                    <asp:BoundField HeaderText="Total" DataField="ITMAMT" ItemStyle-Width="12%" />
                                </Columns>
                                <EmptyDataTemplate>
                                <%--<span style="font-weight:bold; color:Red;">Record Not Found!</span>
                                </EmptyDataTemplate>
                            </asp:GridView>
                        </td>
                    </tr>
                </table>
            </ItemTemplate>
        </asp:DataList>
        </asp:Panel>--%>
    </form>
</body>
</html>


